home *** CD-ROM | disk | FTP | other *** search
- # AlphaTcl - core Tcl engine
-
- namespace eval win {}
-
- proc win::Current {} {global win::Current ; return ${win::Current}}
- proc win::CurrentTail {} {
- global win::Current ; return [file tail ${win::Current}]
- }
- proc win::TopNonProcessWindow {} {
- global win::Active
- foreach f [set win::Active] {
- if {![regexp {^\* .* \*( <[0-9]+>)?$} $f]} {
- return $f
- }
- }
- return ""
- }
- proc win::TopFileWindow {} {
- global win::Active
- foreach f [set win::Active] {
- if {[file exists [win::StripCount $f]]} {
- return $f
- }
- }
- return ""
- }
-
- proc win::StripCount {name} {
- regsub { <[0-9]+>} $name {} name
- return $name
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "win::addToMenu" --
- #
- # Adds a window name to the window menu. This new version adds a
- # binding, to work-around a bug in Alpha, so that using cmd-0-9
- # works if the window name contains square brackets. The problem
- # is that the 'addMenuItem' line creates a binding of the form
- # 'menu::winProc •263 namewith[square]brackets' which when evaluated
- # causes an error. We force a separate binding to
- # 'menu::winProc •263 {namewith[square]brackets}' which does work.
- # -------------------------------------------------------------------------
- ##
- proc win::addToMenu {name} {
- global winNameToNum winMenu winNumToName
- if {[info tclversion] < 8.0} {
- set name [subst $name]
- }
-
- for {set i 0} {$i<100} {incr i} {
- if {![info exists winNumToName($i)]} {
- regsub { <[0-9]+>$} $name {} nm
- if {[file exists $nm]} {
- set nm [file tail $name]
- } else {
- set nm $name
- }
- if {$i < 10} {
- addMenuItem -m -l "/$i" $winMenu "$nm"
- if {[info tclversion] < 8.0} {
- Bind '$i' <c> [list menu::winProc $winMenu $nm]
- }
- } else {
- addMenuItem -m -l "" $winMenu "$nm"
- }
- set winNumToName($i) $name
- set winNameToNum($name) $i
- return
- }
- }
- }
-
- proc win::removeFromMenu {name} {
- global winNameToNum winNumToName winMenu
- if {[info tclversion] < 8.0} {
- set name [subst $name]
- }
- set num $winNameToNum($name)
- unset winNumToName($num)
- unset winNameToNum($name)
- regsub { <[0-9]+>$} $name {} nm
- if {[file exists $nm]} {
- set nm [file tail $name]
- } else {
- # in case it was a file but the file was actually moved!
- global file::separator tcl_platform
- if {[regexp "\[^${file::separator}\]+\$" $name nm]} {
- if {![catch {deleteMenuItem -m $winMenu $nm}]} { return }
- }
- if {$tcl_platform(platform) == "windows"} {
- if {[regexp "\[^\\\\\]+\$" $name nm]} {
- if {![catch {deleteMenuItem -m $winMenu $nm}]} { return }
- }
- }
- set nm $name
- }
- # to handle alpha problem with rebuilding the menu
- if {[catch {deleteMenuItem -m $winMenu $nm}]} {
- deleteMenuItem $winMenu $nm
- }
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "win::setMode" --
- #
- # Copes with endings like '.orig' or the backup ending '~' or '
- # copy'.
- #
- # -------------------------------------------------------------------------
- ##
- proc win::setMode name {
- global win::Modes
- set win::Modes($name) [win::FindMode $name]
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "win::setInitialMode" --
- #
- # Only to be called the very first time we set a window's mode, since
- # it may have all sorts of side-effects.
- # -------------------------------------------------------------------------
- ##
- proc win::setInitialMode {winname mode} {
- global win::Modes
- set win::Modes($winname) $mode
-
- global tabSize ${mode}modeVars
- if {[info exists ${mode}modeVars(tabSize)]} {
- # The mode that the new window will open up in
- # has its own value for tabSize
- win::setInitialConfig $winname tabsize [set ${mode}modeVars(tabSize)]]
- }
-
- # If someone wants a hook here for some reason, please ask!
- #hook::callAll initialModeSetHook $mode $winname
- }
-
- proc win::setInitialConfig {winname option value} {
- global win::config
- lappend win::config($winname) [list $option $value]
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "win::FindMode" --
- #
- # Copes with trailing '<2>', .orig, copy, '~',...
- # -------------------------------------------------------------------------
- ##
- proc win::FindMode {name} {
- global ModeSuffixes
- regsub { <[0-9]+>$} $name "" nm
- regsub {( copy|~[0-9]*|.orig|.in)+$} [file tail $nm] "" nm
- case $nm in $ModeSuffixes
- return $winMode
- }
-
- if {![llength [info commands win::Encoding]]} {
- proc win::Encoding {args} {
- switch -- [llength $args] {
- 0 {
- return "macRoman"
- }
- 1 {
- # encoding of 'name = [lindex $args 0]'
- return "macRoman"
- }
- 2 {
- # set encoding of [lindex $args 0] to [lindex $args 1]
- # not implemented in Alpha 7 or 8 yet.
- return ""
- }
- default {
- error "Wrong number of arguments"
- }
- }
- }
-
- }
-
- ##
- # ----------------------------------------------------------------------
- #
- # "win::searchAndHyperise" --
- #
- # Scans through an entire file for a particular string or regexp, and
- # attaches a hyperlink of the specified form (regsub'ed if desired)
- # to the original string.
- #
- # Side effects:
- # Many hyperlinks will be embedded in your file
- #
- # Arguments:
- # Look for 'text', replace with 'link', doing both with a regexp
- # if signified (regexp = 1), using colour 'col', and offsetting
- # the link start and end by 'startoff' and 'endoff' respectively.
- # This last bit is so you can search for a large pattern, but only
- # embed a link in a smaller part of it.
- #
- # Examples:
- # see 'proc install::hyperiseUrls'
- # ----------------------------------------------------------------------
- ##
- proc win::searchAndHyperise {text link {regexp 0} {col 3} {startoff 0} {endoff 0}} {
- set pos [minPos]
- catch {
- while 1 {
- set inds [search -s -f 1 -r $regexp -- $text $pos]
- set from [lindex $inds 0]
- set to [lindex $inds 1]
- set realfrom $from
- set realto $to
- set realfrom [pos::math $realfrom + $startoff]
- set realto [pos::math $realto + $endoff]
- text::color $realfrom $realto $col
- if {$link != ""} {
- if {$regexp} {
- regsub -- $text [getText $from $to] "$link" llink
- } else {
- set llink $link
- }
- # hack to handle some links.
- regsub -- "<<" $llink "" llink
- regsub -- ">>" $llink "" llink
- if {[pos::diff $realfrom $realto] < 100} {
- text::hyper $realfrom $realto $llink
- } else {
- # Should turn this into an error in the future.
- message "Tried to mark very large hyper."
- }
- }
- set pos $to
- }
- }
- refresh
- }
- proc win::multiSearchAndHyperise {args} {
- while 1 {
- set text [lindex $args 0]
- set link [lindex $args 1]
- set args [lrange $args 2 end]
- if {$text == ""} {return}
- win::searchAndHyperise $text $link
- }
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "win::jumpToCode" --
- #
- # It creates a hyperlink to a specific string in a code file, without
- # requiring a mark to be defined there. It was handy for identifying places
- # in other packages that potentially collide with my key-bindings.
- #
- # Author: Jon Guyer.
- # -------------------------------------------------------------------------
- ##
- proc win::jumpToCode {text file code} {
- set hyper {edit -c }
- append hyper $file
- append hyper { ; set pos [search -f 1 -r 1 "}
- append hyper $code
- append hyper {"] ; select [lindex $pos 0] [lindex $pos 1]}
- win::searchAndHyperise $text $hyper 0 3
- }
-
-